<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>电影信息</title>
    <script>
        function goToTicketPage() {
            // 检查是否有用户名参数，这里简单假设通过 URL 参数判断是否登录
            const urlParams = new URLSearchParams(window.location.search);
            const username = urlParams.get('username');
            if (!username) {
                window.location.href = '/login';
            } else {
                const mid = urlParams.get('mid');
                const mtitle = document.getElementById('movieTitle').textContent;
                window.location.href = `/ticketPage?mid=${mid}&username=${username}&mtitle=${encodeURIComponent(mtitle)}`;
            }
        }
    </script>
</head>
<body>
<h1>电影信息</h1>
<p>电影 ID: <span th:text="${movie.mid}"></span></p>
<p>电影标题: <span id="movieTitle" th:text="${movie.mtitle}"></span></p>
<p>上映日期: <span th:text="${movie.mdate}"></span></p>
<p>时长: <span th:text="${movie.mruntime}"></span></p>
<p>评分: <span th:text="${movie.rating}"></span></p>
<p>投票数: <span th:text="${movie.vote_count}"></span></p>
<p>状态: <span th:text="${movie.status}"></span></p>
<p>价格: <span th:text="${movie.price}"></span></p>
<p>电影类型:
    <span th:each="geners : ${movie.geners}" th:text="${geners.gname}" th:if="${not #lists.isEmpty(movie.geners)}" th:attr="data-gid=${geners.gid}">
        <span th:if="${not #lists.last(movie.geners, geners)}">, </span>
    </span>
    <span th:if="${#lists.isEmpty(movie.geners)}">无</span>
</p>
<p>导演:
    <span th:each="director : ${movie.directors}" th:text="${director.dname}" th:if="${not #lists.isEmpty(movie.directors)}" th:attr="data-did=${director.did}">
        <span th:if="${not #lists.last(movie.directors, director)}">, </span>
    </span>
    <span th:if="${#lists.isEmpty(movie.directors)}">无</span>
</p>
<p>演员:
    <span th:each="actor : ${movie.actors}" th:text="${actor.aname}" th:if="${not #lists.isEmpty(movie.actors)}" th:attr="data-aid=${actor.aid}">
        <span th:if="${not #lists.last(movie.actors, actor)}">, </span>
    </span>
    <span th:if="${#lists.isEmpty(movie.actors)}">无</span>
</p>

<h2>评论列表</h2>
<ul>
    <li th:each="review : ${reviews}">
        <p>评论 ID: <span th:text="${review.rid}"></span></p>
        <p>用户名: <span th:text="${review.uid}"></span></p>
        <p>评论内容: <span th:text="${review.content}"></span></p>
        <p>评分: <span th:text="${review.rating}"></span></p>
        <p>评论时间: <span th:text="${review.markTime}"></span></p>
    </li>
</ul>

<!-- 修改购票按钮 -->
<button onclick="goToTicketPage()">购票</button>

<a th:href="@{/successPage(username=${username}, page=0, size=10)}">返回电影列表</a>
</body>
</html>